# -*- coding: utf-8 -*-

# @Project : UI_DDTFrameWork
# @Author  : Mr.Deng
# @Time    : 2021/9/22 0:14

from page import BasePage
from common.tools.decorator import error_collection
from config.urlConfig import *

from selenium.webdriver.common.by import By


class BaiDuSetPage(BasePage):
    """
    百度首页设置
    """
    setBtn = (By.XPATH, '//*[@id="s-usersetting-top"]')
    closeHotSearchBtn = (By.XPATH, '//a[text()="关闭热搜"]')
    openHotSearchBtn = (By.XPATH, '//a[text()="开启热搜"]')
    hideAttributeBtn = (By.XPATH, '//*[@id="s-hotsearch-wrapper"]')

    def open_search_home_page(self):
        """
        打开百度首页
        :return:
        """
        self.driver.open_url(host)

    def move_set_btn(self):
        """
        鼠标移动到设置按钮
        :return:
        """
        self.driver.move_on_element(self.setBtn)

    @error_collection
    def click_hide_show_info_btn(self, btnName: str):
        """
        打开百度首页
        :param btnName: 索要点击的按钮名称
        :return:
        """
        if btnName == "开启":
            if self.driver.get_is_displayed(self.openHotSearchBtn):
                self.driver.move_and_click(self.openHotSearchBtn)
        elif btnName == "关闭":
            if self.driver.get_is_displayed(self.closeHotSearchBtn):
                self.driver.move_and_click(self.closeHotSearchBtn)
        else:
            raise NameError(f"按钮名称字段：{btnName} 被允许！！！")

    def get_hot_search_btn_att(self) -> str:
        """
        获取首页热搜模块是否可见，属性
        :return:
        """
        return self.driver.get_attribute_value(self.hideAttributeBtn, "class")